#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=1610,MAXM=3e4+10;
int n,m,dis[MAXN],S,T,flow,cost,head[MAXN],cnt,a[MAXN];
bool vis[MAXN];
struct edge
{
	int v,next,flow,cost;
}e[MAXM<<1];
void addedge(int x,int y,int f,int c)
{
	e[cnt]=(edge){y,head[x],f,c};
	head[x]=cnt++;
	swap(x,y);
	e[cnt]=(edge){y,head[x],0,-c};
	head[x]=cnt++;
	return;
}
int aug(int u,int _min)
{
	vis[u]=true;
	if(u==T)
	{
		flow+=_min;
		cost+=_min*dis[S];
		return _min;
	}
	int ret=0,k;
	for(int i=head[u];~i;i=e[i].next)
	{
		int v=e[i].v;
		if(vis[v]||!e[i].flow||dis[v]-dis[u]+e[i].cost)continue;
		k=aug(v,min(_min-ret,e[i].flow));
		e[i].flow-=k;
		e[i^1].flow+=k;
		ret+=k;
		if(ret==_min)break;
	}
	return ret;
}
bool mdf()
{
	int _min=INF;
	for(int u=S;u<=T;++u)
	{
		if(!vis[u])continue;
		for(int i=head[u];~i;i=e[i].next)
		{
			int v=e[i].v;
			if(!e[i].flow||vis[v])continue;
			_min=min(_min,dis[v]-dis[u]+e[i].cost);
		}
	}
	if(_min==INF)return false;
	for(int i=S;i<=T;++i)
		if(vis[i])
			dis[i]+=_min;
	return true;
}
void zkw()
{
	do do memset(vis,0,sizeof(vis));
	while(aug(S,INF));
	while(mdf());
	return;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=read();m=read();
	memset(head,-1,sizeof(head));
	T=n*2+1;
	for(int i=1;i<=n;++i)addedge(S,i*2,1,read()),addedge(S,i*2-1,1,0),addedge(i*2,T,1,0);
	for(int i=1;i<=m;++i)
	{
		int x=read(),y=read(),z=read();
		addedge(min(x,y)*2-1,max(x,y)*2,1,z);
	}
	zkw();
	printf("%d\n",cost);
	return 0;
}
